-
-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: useEventListener
EventMap generic override + EventTarget
& refactor: multiple overloads to single mapped type
#657
base: master
Are you sure you want to change the base?
Conversation
|
…(intersect with DocumentEventMap for document listeners)
…laration & (removed unnecessary document map intersection)
…all within other hooks
…ig ref to element
useEventListener
Element to Event Map generic override & refactor: multiple overloads to single mapped typeuseEventListener
Element to Event Map generic override + EventTarget
& refactor: multiple overloads to single mapped type
useEventListener
Element to Event Map generic override + EventTarget
& refactor: multiple overloads to single mapped typeuseEventListener
Element to Event Map generic override + EventTarget
#585 & refactor: multiple overloads to single mapped type
useEventListener
Element to Event Map generic override + EventTarget
#585 & refactor: multiple overloads to single mapped typeuseEventListener
Element to Event Map generic override + EventTarget
& refactor: multiple overloads to single mapped type
useEventListener
Element to Event Map generic override + EventTarget
& refactor: multiple overloads to single mapped typeuseEventListener
EventMap generic override + EventTarget
& refactor: multiple overloads to single mapped type
Changelog
This PR introduces several improvements aimed at reducing complexity and increasing flexibility in the codebase:
🔨 Refactor: Reduced Code Duplication:
✨ Feature: Enhanced Type Safety:
config.element
argument) + AudioNode...🔨 Refactor: Parameter Simplification:
config
.In Depth Changes
🔨 Refactor: Improved Readability & future refactors (by decreasing code size)
Replaced Overloads with Generic map from Element (string) to [Element, EventMap] tuple + 2 Utility constructs
✨ Feature: Enhanced Type Safety
Custom EventMap Generic (overrides all Event to Element Mapping declarations in hook)
Globally declared CustomEventMap always available (applied to all DOM Elements, except when custom generic is used)
🔨 Refactor Parameter Simplification
Optional Arguments
element?: RefObject<T>
&options?: boolean | AddEventListenerOptions
moved to single optional Object argumentconfig
Adding a new ref Element to Event map
Previously an overload was needed (+6 lines). Now adding a key-value pair to the ElementToEventMap: which value is a tuple containing the element type and its corresponding event map type (+1 line)
Usage Preview